<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Request
 *
 * @author wlf
 */

if(!defined('TinyFW')) exit('Access denied!');

class tfRequest {

    private $request = array('GET' => null, 'POST'=> null,'PUT'=>null, 'DELETE'=>null);
    
    private static $instance;

    private function __construct() {
        
    }

    public function __clone() { }

    public static function singleton() {
        if(! isset (self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    private function set($type, $key, $value) {
        $this->request[$type][$key] = $value;
    }

    private function set_array($type, $arr_value) {
        if(isset($this->$request[$type])) {
            $this->$request[$type] = array_merge($this->request[$type],$arr_value);
        } else {
            $this->request[$type] = $arr_value;
        }
    }

    private function get($type, $key) {
        return $this->request[$type][$key];
    }
    

    public static function getGetParameter($key) {
        return self::singleton()->get('GET',$key);
    }

    public static function getPostParameter($key) {
        return self::singleton()->get('POST',$key);
    }

    public static function getPutParameter($key) {
        return self::singleton()->get('PUT',$key);
    }

    public static function getDeleteParameter($key) {
        return self::singleton()->get('DELETE',$key);
    }

    
    public static function setGetParameter($key, $value) {
        $num = func_num_args();
        $args = func_get_args();

        if($num == 1) {
            return self::singleton()->set_array('GET',$args[0]);
        } elseif ($num == 2) {
            return self::singleton()->set('GET',$args[0],$args[1]);
        }
        //self::singleton()->set('GET',$key, $value);
    }

    public static function setPostParameter() {
        $num = func_num_args();
        $args = func_get_args();
        
        if($num == 1) {
            return self::singleton()->set_array('POST',$args[0]);
        } elseif ($num == 2) {
            return self::singleton()->set('POST',$args[0],$args[1]);
        }
        //self::singleton()->set('POST',$key, $value);
    }

    public static function setPutParameter($key, $value) {
        self::singleton()->set('PUT',$key, $value);
    }

    
    public static function setDeleteParameter($key, $value) {
        self::singleton()->set('DELETE',$key, $value);
    }

    private function getRequest() {
        return $this->request;
    }
    
    public static function printParameters() {
        echo "<pre>";
        print_r(self::singleton()->getRequest());
        
        echo "</pre>";
    }
    
}
?>
